package net.maxwoods.nimble.spring.security;

import org.springframework.core.annotation.Order;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;

public class CustomLoginFilter extends AbstractAuthenticationProcessingFilter {


    public CustomLoginFilter(String defaultFilterProcessesUrl)
    {
        super(defaultFilterProcessesUrl);
    }

    @Override
    public Authentication attemptAuthentication(HttpServletRequest request,
                                                HttpServletResponse response) throws AuthenticationException
    {
        CustomWebAuthenticationDetails customWebAuthenticationDetails=new CustomWebAuthenticationDetails(request);
        CustomAuthenticationToken token=new CustomAuthenticationToken(customWebAuthenticationDetails,"b",new ArrayList<CustomeGrantedAuthority>());
        token.setDetails(customWebAuthenticationDetails);
        return getAuthenticationManager().authenticate(token);
    }
}
